package com.xuanyue.db.xuan;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import com.xuanyue.db.xuan.core.orm.OrmUtils;
import com.xuanyue.db.xuan.core.table.expr.ExprValue;
import com.xuanyue.db.xuan.core.table.expr.ExprValueType;

public class Phone {
	private List<Integer> c_phone;
	private int c_Operator;
	private Integer C_Utiid;
	private float C_MarketPrice;
	private int C_ProId;
	private int C_CityId;
	private Boolean C_IsMy;
	private boolean C_IsYd;
	private boolean C_IsEnable;
	private boolean C_IsSuperGood;
	private boolean C_IsHome;
	private Map<String,Boolean> C_IsNominate;
	private Map<String,Boolean> C_IsSpecial;
	
	private int C_IsShelves;
	private boolean C_IsCostEffective;
	public List<Integer> getC_phone() {
		return c_phone;
	}
	public void setC_phone(List<Integer> c_phone) {
		this.c_phone = c_phone;
	}
	public int getC_Operator() {
		return c_Operator;
	}
	public void setC_Operator(int c_Operator) {
		this.c_Operator = c_Operator;
	}
	public Integer getC_Utiid() {
		return C_Utiid;
	}
	public void setC_Utiid(int c_Utiid) {
		C_Utiid = c_Utiid;
	}
	public float getC_MarketPrice() {
		return C_MarketPrice;
	}
	public void setC_MarketPrice(float c_MarketPrice) {
		C_MarketPrice = c_MarketPrice;
	}
	public int getC_ProId() {
		return C_ProId;
	}
	public void setC_ProId(int c_ProId) {
		C_ProId = c_ProId;
	}
	public int getC_CityId() {
		return C_CityId;
	}
	public void setC_CityId(int c_CityId) {
		C_CityId = c_CityId;
	}
	public boolean isC_IsMy() {
		return C_IsMy;
	}
	public void setC_IsMy(boolean c_IsMy) {
		C_IsMy = c_IsMy;
	}
	public boolean isC_IsYd() {
		return C_IsYd;
	}
	public void setC_IsYd(boolean c_IsYd) {
		C_IsYd = c_IsYd;
	}
	public boolean isC_IsEnable() {
		return C_IsEnable;
	}
	public void setC_IsEnable(boolean c_IsEnable) {
		C_IsEnable = c_IsEnable;
	}
	public boolean isC_IsSuperGood() {
		return C_IsSuperGood;
	}
	public void setC_IsSuperGood(boolean c_IsSuperGood) {
		C_IsSuperGood = c_IsSuperGood;
	}
	public boolean isC_IsHome() {
		return C_IsHome;
	}
	public void setC_IsHome(boolean c_IsHome) {
		C_IsHome = c_IsHome;
	}
	public Map<String, Boolean> getC_IsNominate() {
		return C_IsNominate;
	}
	public void setC_IsNominate(Map<String, Boolean> c_IsNominate) {
		C_IsNominate = c_IsNominate;
	}
	public Map<String, Boolean> getC_IsSpecial() {
		return C_IsSpecial;
	}
	public void setC_IsSpecial(Map<String, Boolean> c_IsSpecial) {
		C_IsSpecial = c_IsSpecial;
	}
	public int getC_IsShelves() {
		return C_IsShelves;
	}
	public void setC_IsShelves(int c_IsShelves) {
		C_IsShelves = c_IsShelves;
	}
	public boolean isC_IsCostEffective() {
		return C_IsCostEffective;
	}
	public void setC_IsCostEffective(boolean c_IsCostEffective) {
		C_IsCostEffective = c_IsCostEffective;
	}
	
	public List<ExprValue> getNumbers(){
		List<ExprValue> r = new ArrayList<>();
		for(int i=0;i<11;i++) {
			r.add(new ExprValue(ExprValueType.LONG,  this.c_phone.get(i) ));
		}
		return r;
	}
	
	private ExprValue getC2P(){
		Map<String, ExprValue> r = new HashMap<>();
		
		r.put("c_phone",new ExprValue(ExprValueType.ARRAY, getNumbers()));
		r.put("c_Operator", new ExprValue(ExprValueType.INT,c_Operator));
		r.put("C_Utiid", new ExprValue(ExprValueType.INT,C_Utiid));
		r.put("C_MarketPrice", new ExprValue(ExprValueType.FLOAT,C_MarketPrice));
		r.put("C_ProId", new ExprValue(ExprValueType.INT,C_ProId));
		r.put("C_CityId", new ExprValue(ExprValueType.INT,C_CityId));
		
		r.put("C_IsMy", new ExprValue(ExprValueType.BOOLEAN,C_IsMy));
		r.put("C_IsYd", new ExprValue(ExprValueType.BOOLEAN,C_IsYd));
		r.put("C_IsEnable", new ExprValue(ExprValueType.BOOLEAN,C_IsEnable));
		r.put("C_IsSuperGood", new ExprValue(ExprValueType.BOOLEAN,C_IsSuperGood));
		r.put("C_IsHome", new ExprValue(ExprValueType.BOOLEAN,C_IsHome));
		
		Map<String,ExprValue> x = new HashMap<>();
		for(Entry<String,Boolean> en:C_IsNominate.entrySet()) {
			x.put(en.getKey(), new ExprValue(ExprValueType.BOOLEAN,en.getValue()));
		}
		r.put("C_IsNominate", new ExprValue(ExprValueType.MAP,x));
		
		x = new HashMap<>();
		for(Entry<String,Boolean> en:C_IsSpecial.entrySet()) {
			x.put(en.getKey(), new ExprValue(ExprValueType.BOOLEAN,en.getValue()));
		}
		r.put("C_IsSpecial", new ExprValue(ExprValueType.MAP,x));
		
		r.put("C_IsShelves", new ExprValue(ExprValueType.INT,C_IsShelves));
		r.put("C_IsCostEffective", new ExprValue(ExprValueType.BOOLEAN,C_IsCostEffective));
		return new ExprValue(ExprValueType.MAP,r);
	}
	public static List<ExprValue> getR(int s,java.util.Random random){
		List<ExprValue> r = new ArrayList<>();
		Phone ph = new Phone();
		for(int i=0;i<s;i++) {
			ph.init(random);
			r.add(ph.getC2P());
		}
		return r;
	}
	
	private void flushNumber(java.util.Random random) {
		this.c_phone.clear();
		this.c_phone.add(1);
		this.c_phone.add(3+random.nextInt(7));
		this.c_phone.add(random.nextInt(9));
		
		this.c_phone.add(random.nextInt(9));
		this.c_phone.add(random.nextInt(9));
		this.c_phone.add(random.nextInt(9));
		this.c_phone.add(random.nextInt(9));
		this.c_phone.add(random.nextInt(9));
		this.c_phone.add(random.nextInt(9));
		this.c_phone.add(random.nextInt(9));
		this.c_phone.add(random.nextInt(9));
	}
	
	public void init(java.util.Random random) {
		
		flushNumber(random);
		c_Operator = random.nextInt(4);
		C_Utiid = random.nextInt(100000);
		C_MarketPrice = random.nextInt(100000001);
		C_MarketPrice/=100;
		C_ProId = random.nextInt(64);
		C_CityId = random.nextInt(1024);
		C_IsMy = (random.nextInt(10)<5);
		C_IsYd= (random.nextInt(10)<5);
		C_IsEnable= (random.nextInt(10)<5);
		C_IsSuperGood = (random.nextInt(10)<5);
		C_IsHome = (random.nextInt(10)<5);
		C_IsNominate = new HashMap<>();
		C_IsNominate.put("zhw", (random.nextInt(10)<5));
		C_IsNominate.put("xxh", (random.nextInt(10)<5));
		C_IsNominate.put("sjh", (random.nextInt(10)<5));
		C_IsNominate.put("mix3to1", (random.nextInt(10)<5));
		C_IsNominate.put("qg", (random.nextInt(10)<5));
		C_IsNominate.put("test", (random.nextInt(10)<5));
		C_IsShelves = random.nextInt(4);
		C_IsCostEffective = (random.nextInt(10)<5);
		
	}
	
	
	private void ph() {
		for(int x:c_phone) {
			System.out.print(x);
		}
		System.out.println();
	}
	public static void main(String[] args) throws Exception {
		
		java.util.Random random = new java.util.Random();
		Phone ph = new Phone();
		ph.setC_phone(new ArrayList<>());
		ph.setC_IsNominate(new HashMap<>());
		ph.setC_IsSpecial(new HashMap<>());
		ph.init(random);
		
		ExprValue ex = OrmUtils.obj2ExprValue(ph);
		System.out.println(ex);
		ph.ph();
		Phone phx = OrmUtils.exprValue2Obj(ex, Phone.class);
		phx.ph();
	}
	
	
}
